package ca.magex.gps.loader;

import java.io.InputStream;
import java.util.List;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import ca.magex.gps.entity.impl.GarminTrack;

public class Importer {

	public static List<GarminTrack> parse(InputStream is, XmlType type) throws ImporterException {
		try {
			SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
			FileHandler handler;
			if (type == XmlType.LOAD_MY_TRACKS)
				handler = new LoadMyTracksFileHandler();
			else 
				throw new ImporterException("Invalid xml type " + type);
			parser.parse(is, handler);
			return handler.getData();
		} catch (Exception e) {
			throw new ImporterException(e);
		}
	}
	
}
